var QTYYSysUserMain = function() {
	// 用户主页面属性开始
	var sysUserTableId = "sysUserTable";
	var $sysUserTable = $("#sysUserTable");
	var tableAjaxUrl = "sysUser/page/list";
	var $addSysUserView = $("#addSysUserView");
	var $updateSysUserView = $("#updateSysUserView");
	var $deleteSysUsers = $("#deleteSysUsers");
	var sysUserTableColum = [ {
		checkbox : true
	}, {
		title : 'id',
		field : 'id',
		align : 'center',
		valign : 'middle',
		visible : false
	}, {
		title : '登录账号',
		field : 'username',
		align : 'center',
		valign : 'middle'
	}, {
		title : '用户名称',
		field : 'realname',
		align : 'center',
		valign : 'middle'
	}, {
		title : '用户性别',
		field : 'sex',
		align : 'center',
		valign : 'middle',
		formatter : function(value, row, index) {
			if (value == 1) {
				return "男";
			} else if (value == 2) {
				return "女";
			} else {
				return "未知";
			}
		}
	}, {
		title : '用户状态',
		field : 'activeFlag',
		align : 'center',
		formatter : function(value, row, index) {
			if (value == 1) {
				return "正常";
			} else if (value == -1) {
				return "锁定";
			} else {
				return "未知";
			}
		}
	} ];
	// 用户主页面属性结束

	// 用户列表搜索开始
	var searchSysUserFormId = "searchSysUserForm";
	var $searchSysUserForm = $("#searchSysUserForm");
	var $searchSysUsersBtn = $("#searchSysUsersBtn");
	// 用户列表搜索结束

	/**
	 * 用户主页面初始化用户表格数据
	 */
	var initTable = function() {
		QTYYComponentsTable.initBootStrapTable($sysUserTable, tableAjaxUrl, sysUserTableColum);
	}
	/**
	 * 绑定按钮事件
	 */
	var sysUserMainEventHandler = function() {
		// 绑定查询按钮
		$searchSysUsersBtn.on("click", function() {
			QTYYComponentsTable.searchTable(sysUserTableId, searchSysUserFormId);
		});

		// 绑定增加用户弹出页面的按钮事件
		$addSysUserView.on("click", function() {
			layerIndex = QTYYComponents.layerOpen("添加用户信息", '1000px', '650px', "sysUser/add/view");
		});
		// 绑定修改用户弹出页面的按钮事件
		$updateSysUserView.on("click",
				function() {
					var rows = QTYYComponentsTable.getTableSelections($sysUserTable);
					if (rows.length == 0) {
						QTYYComponents.bootstrapSweetAlert("", "请选择一个用户", "error");
						return;
					}
					if (rows.length >= 2) {
						QTYYComponents.bootstrapSweetAlert("", "不能选择多个用户", "error");
						return;
					}
					// 查看用户的基本信息
					QTYYComponents.layerOpen("修改用户信息", '1000px', '650px', "sysUser/update/view/" + rows[0].id
							+ "?operator=1");
				});
		// 绑定删除按钮事件
		$deleteSysUsers.on("click", function() {
			QTYYComponentsTable.ajaxDeleteTable("sysUser/delete", $sysUserTable);
		});
	}

	return {
		initSysUserMain : function() {
			initTable();
			sysUserMainEventHandler();
		}
	}
}();
